home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Online / NNTPd / server / newgroups.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-11-01  |  2.9 KB  |  134 lines

  1. #ifndef lint
  2. static char    sccsid[] = "@(#)newgroups.c    1.13    (Berkeley) 2/6/88";
  3. #endif
  4.  
  5. #include "common.h"
  6. #include "date.h"
  7.  
  8. /*
  9.  * NEWGROUPS date time ["GMT"] [<distributions>]
  10.  *
  11.  * Display new newsgroups since a given date and time, but only
  12.  * for those in <distributions>.
  13.  */
  14.  
  15. void
  16. newgroups(argc, argv)
  17.     int        argc;
  18.     char        *argv[];
  19. {
  20.     char        line[NNTP_STRLEN];
  21.     register char    *cp;
  22.     static char    **dist_list = (char **) NULL;
  23.     int        distcount = 0;
  24.     int        i, low_msg, high_msg;
  25.     long        date;
  26.     register FILE    *date_fp;
  27.     char        *reqlist[2];
  28.  
  29.     if (argc < 3) {
  30. printf("%d Usage: NEWGROUPS yymmdd hhmmss [\"GMT\"] [<distributions>].\r\n",
  31.             ERR_CMDSYN);
  32.         (void) fflush(stdout);
  33.         return;
  34.     }
  35.  
  36.     date_fp = fopen(activetimesfile, "r");
  37.     if (date_fp == NULL) {
  38. #ifdef SYSLOG
  39.         syslog(LOG_ERR, "newgroups: fopen %s: %m", activetimesfile);
  40. #endif
  41.         printf("%d Cannot open active.times file.\r\n", ERR_FAULT);
  42.         (void) fflush(stdout);
  43.         return;
  44.     }
  45.  
  46.     /*        YYMMDD            HHMMSS    */
  47.     if (strlen(argv[1]) != 6 || strlen(argv[2]) != 6) {
  48.         printf("%d Date/time must be in form YYMMDD HHMMSS.\r\n",
  49.             ERR_CMDSYN);
  50.         (void) fflush(stdout);
  51.         (void) fclose(date_fp);
  52.         return;
  53.     }
  54.  
  55.     (void) strcpy(line, argv[1]);            /* yymmdd */
  56.     (void) strcat(line, argv[2]);            /* hhmmss */
  57.  
  58.     date = dtol(line);
  59.     if (date < 0) {
  60.         printf("%d Invalid date specification.\r\n", ERR_CMDSYN);
  61.         (void) fflush(stdout);
  62.         (void) fclose(date_fp);
  63.         return;
  64.     }
  65.  
  66.     argc -= 3;
  67.     argv += 3;
  68.  
  69.     if (argc > 0 && !strcasecmp(*argv, "GMT")) { /* We store stuff in GMT */
  70.         ++argv;                /* anyway, so this is */
  71.         --argc;                /* a "noop" */
  72.     } else                     /* But that means not GMT */
  73.         date = local_to_gmt(date);    /* is a definite "op" */
  74.  
  75.     if (argc > 0) {
  76.         distcount = get_distlist(&dist_list, *argv);
  77.         if (distcount < 0) {
  78.             printf("%d Bad distribution list: %s\r\n",
  79.                 ERR_CMDSYN, *argv);
  80.             (void) fflush(stdout);
  81.             (void) fclose(date_fp);
  82.             return;
  83.         }
  84.     }
  85.  
  86.     printf("%d New newsgroups since %s follow.\r\n", OK_NEWGROUPS, line);
  87.  
  88.     while (fgets(line, sizeof(line), date_fp) != NULL) {
  89.         if ((cp = index(line, '\n')) != NULL)
  90.             *cp = '\0';
  91.         if ((cp = index(line, ' ')) != NULL)
  92.             *cp = '\0';
  93.         if (atoi(cp + 1) < date)
  94.             continue;
  95.  
  96.         if (distcount == 0) {
  97.             reqlist[0] = line;
  98.             reqlist[1] = NULL;
  99.  
  100.             if (ngpermcount) {
  101.                 if (ngmatch(s1strneql, ALLBUT, ngpermlist,
  102.                         ngpermcount, reqlist, 1) == 0) {
  103.                     continue;
  104.                 }
  105.             } else if (ALLBUT == 0)
  106.                 continue;
  107.         } else {
  108.             cp = index(line, '.');
  109.             if (cp == NULL)
  110.                 continue;
  111.             *cp = '\0';
  112.             for (i = 0; i < distcount; ++i) {
  113.                 if (strcmp(line, dist_list[i]) == 0) {
  114.                     *cp = '.';
  115.                     break;
  116.                 }
  117.             }
  118.             if (i == distcount)
  119.                 continue;
  120.         }
  121.         i = find_group(line, &low_msg, &high_msg);
  122.         if (i < 0)
  123.             continue;
  124.         cp = group_array[i] + strlen(line);
  125.         while (isdigit(*cp) || isspace(*cp)) cp++;
  126.         if (*cp == '\0' || *cp == 'x' || *cp == '=')
  127.             continue;
  128.         putline(group_array[i]);
  129.     }
  130.     putline(".");
  131.     (void) fflush(stdout);
  132.     (void) fclose(date_fp);
  133. }
  134.